﻿namespace Microsoft.SharePoint.Client
{
    using System;
    using System.ComponentModel;

    [ScriptType("SP.UserCustomAction", ServerTypeId="{232f8709-5dfd-44cf-a35b-7d8538c9336e}")]
    public class UserCustomAction : ClientObject
    {
        [EditorBrowsable(EditorBrowsableState.Never)]
        public UserCustomAction(ClientRuntimeContext Context, ObjectPath ObjectPath) : base(Context, ObjectPath)
        {
        }

        [Remote]
        public virtual void DeleteObject()
        {
            ClientAction query = new ClientActionInvokeMethod(this, "DeleteObject", null);
            base.Context.AddQuery(query);
            base.RemoveFromParentCollection();
        }

        protected override bool InitOnePropertyFromJson(string peekedName, JsonReader reader)
        {
            bool flag = base.InitOnePropertyFromJson(peekedName, reader);
            if (!flag)
            {
                switch (peekedName)
                {
                    case "Name":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["Name"] = reader.ReadString();
                        return flag;

                    case "Title":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["Title"] = reader.ReadString();
                        return flag;

                    case "Description":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["Description"] = reader.ReadString();
                        return flag;

                    case "Scope":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["Scope"] = reader.ReadEnum<UserCustomActionScope>();
                        return flag;

                    case "Sequence":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["Sequence"] = reader.ReadInt32();
                        return flag;

                    case "Id":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["Id"] = reader.ReadGuid();
                        return flag;

                    case "ImageUrl":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["ImageUrl"] = reader.ReadString();
                        return flag;

                    case "RegistrationType":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["RegistrationType"] = reader.ReadEnum<UserCustomActionRegistrationType>();
                        return flag;

                    case "RegistrationId":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["RegistrationId"] = reader.ReadString();
                        return flag;

                    case "Url":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["Url"] = reader.ReadString();
                        return flag;

                    case "Location":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["Location"] = reader.ReadString();
                        return flag;

                    case "ScriptSrc":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["ScriptSrc"] = reader.ReadString();
                        return flag;

                    case "ScriptBlock":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["ScriptBlock"] = reader.ReadString();
                        return flag;

                    case "Group":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["Group"] = reader.ReadString();
                        return flag;

                    case "CommandUIExtension":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["CommandUIExtension"] = reader.ReadString();
                        return flag;

                    case "VersionOfUserCustomAction":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["VersionOfUserCustomAction"] = reader.ReadString();
                        return flag;

                    case "Rights":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["Rights"] = reader.Read<BasePermissions>();
                        return flag;
                }
            }
            return flag;
        }

        [Remote]
        public virtual void Update()
        {
            ClientAction query = new ClientActionInvokeMethod(this, "Update", null);
            base.Context.AddQuery(query);
            this.RefreshLoad();
        }

        [Remote]
        public string CommandUIExtension
        {
            get
            {
                base.CheckUninitializedProperty("CommandUIExtension");
                return (string) base.ObjectData.Properties["CommandUIExtension"];
            }
            set
            {
                base.ObjectData.Properties["CommandUIExtension"] = value;
                if (base.Context != null)
                {
                    base.Context.AddQuery(new ClientActionSetProperty(this, "CommandUIExtension", value));
                }
            }
        }

        [Remote]
        public string Description
        {
            get
            {
                base.CheckUninitializedProperty("Description");
                return (string) base.ObjectData.Properties["Description"];
            }
            set
            {
                base.ObjectData.Properties["Description"] = value;
                if (base.Context != null)
                {
                    base.Context.AddQuery(new ClientActionSetProperty(this, "Description", value));
                }
            }
        }

        [Remote]
        public string Group
        {
            get
            {
                base.CheckUninitializedProperty("Group");
                return (string) base.ObjectData.Properties["Group"];
            }
            set
            {
                base.ObjectData.Properties["Group"] = value;
                if (base.Context != null)
                {
                    base.Context.AddQuery(new ClientActionSetProperty(this, "Group", value));
                }
            }
        }

        [Remote]
        public Guid Id
        {
            get
            {
                base.CheckUninitializedProperty("Id");
                return (Guid) base.ObjectData.Properties["Id"];
            }
        }

        [Remote]
        public string ImageUrl
        {
            get
            {
                base.CheckUninitializedProperty("ImageUrl");
                return (string) base.ObjectData.Properties["ImageUrl"];
            }
            set
            {
                base.ObjectData.Properties["ImageUrl"] = value;
                if (base.Context != null)
                {
                    base.Context.AddQuery(new ClientActionSetProperty(this, "ImageUrl", value));
                }
            }
        }

        [Remote]
        public string Location
        {
            get
            {
                base.CheckUninitializedProperty("Location");
                return (string) base.ObjectData.Properties["Location"];
            }
            set
            {
                base.ObjectData.Properties["Location"] = value;
                if (base.Context != null)
                {
                    base.Context.AddQuery(new ClientActionSetProperty(this, "Location", value));
                }
            }
        }

        [Remote]
        public string Name
        {
            get
            {
                base.CheckUninitializedProperty("Name");
                return (string) base.ObjectData.Properties["Name"];
            }
            set
            {
                base.ObjectData.Properties["Name"] = value;
                if (base.Context != null)
                {
                    base.Context.AddQuery(new ClientActionSetProperty(this, "Name", value));
                }
            }
        }

        [Remote]
        public string RegistrationId
        {
            get
            {
                base.CheckUninitializedProperty("RegistrationId");
                return (string) base.ObjectData.Properties["RegistrationId"];
            }
            set
            {
                base.ObjectData.Properties["RegistrationId"] = value;
                if (base.Context != null)
                {
                    base.Context.AddQuery(new ClientActionSetProperty(this, "RegistrationId", value));
                }
            }
        }

        [Remote]
        public UserCustomActionRegistrationType RegistrationType
        {
            get
            {
                base.CheckUninitializedProperty("RegistrationType");
                return (UserCustomActionRegistrationType) base.ObjectData.Properties["RegistrationType"];
            }
            set
            {
                base.ObjectData.Properties["RegistrationType"] = value;
                if (base.Context != null)
                {
                    base.Context.AddQuery(new ClientActionSetProperty(this, "RegistrationType", value));
                }
            }
        }

        [Remote]
        public BasePermissions Rights
        {
            get
            {
                base.CheckUninitializedProperty("Rights");
                return (BasePermissions) base.ObjectData.Properties["Rights"];
            }
            set
            {
                if (base.Context.ValidateOnClient && (value == null))
                {
                    throw ClientUtility.CreateArgumentNullException("value");
                }
                base.ObjectData.Properties["Rights"] = value;
                if (base.Context != null)
                {
                    base.Context.AddQuery(new ClientActionSetProperty(this, "Rights", value));
                }
            }
        }

        [Remote]
        public UserCustomActionScope Scope
        {
            get
            {
                base.CheckUninitializedProperty("Scope");
                return (UserCustomActionScope) base.ObjectData.Properties["Scope"];
            }
        }

        [Remote]
        public string ScriptBlock
        {
            get
            {
                base.CheckUninitializedProperty("ScriptBlock");
                return (string) base.ObjectData.Properties["ScriptBlock"];
            }
            set
            {
                base.ObjectData.Properties["ScriptBlock"] = value;
                if (base.Context != null)
                {
                    base.Context.AddQuery(new ClientActionSetProperty(this, "ScriptBlock", value));
                }
            }
        }

        [Remote]
        public string ScriptSrc
        {
            get
            {
                base.CheckUninitializedProperty("ScriptSrc");
                return (string) base.ObjectData.Properties["ScriptSrc"];
            }
            set
            {
                base.ObjectData.Properties["ScriptSrc"] = value;
                if (base.Context != null)
                {
                    base.Context.AddQuery(new ClientActionSetProperty(this, "ScriptSrc", value));
                }
            }
        }

        [Remote]
        public int Sequence
        {
            get
            {
                base.CheckUninitializedProperty("Sequence");
                return (int) base.ObjectData.Properties["Sequence"];
            }
            set
            {
                if (base.Context.ValidateOnClient)
                {
                    if (value < 0)
                    {
                        throw ClientUtility.CreateArgumentException("value");
                    }
                    if (value > 0x10000)
                    {
                        throw ClientUtility.CreateArgumentException("value");
                    }
                }
                base.ObjectData.Properties["Sequence"] = value;
                if (base.Context != null)
                {
                    base.Context.AddQuery(new ClientActionSetProperty(this, "Sequence", value));
                }
            }
        }

        [Remote]
        public string Title
        {
            get
            {
                base.CheckUninitializedProperty("Title");
                return (string) base.ObjectData.Properties["Title"];
            }
            set
            {
                base.ObjectData.Properties["Title"] = value;
                if (base.Context != null)
                {
                    base.Context.AddQuery(new ClientActionSetProperty(this, "Title", value));
                }
            }
        }

        [Remote]
        public string Url
        {
            get
            {
                base.CheckUninitializedProperty("Url");
                return (string) base.ObjectData.Properties["Url"];
            }
            set
            {
                base.ObjectData.Properties["Url"] = value;
                if (base.Context != null)
                {
                    base.Context.AddQuery(new ClientActionSetProperty(this, "Url", value));
                }
            }
        }

        [Remote]
        public string VersionOfUserCustomAction
        {
            get
            {
                base.CheckUninitializedProperty("VersionOfUserCustomAction");
                return (string) base.ObjectData.Properties["VersionOfUserCustomAction"];
            }
        }
    }
}

